﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;

namespace TCHSHue.Modules.AdminControl.HoSo
{
    public partial class ctrHoSo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void RedirectEdit(object sender, CommandEventArgs e)
        {
            Response.Redirect("~/Modules/Admin.aspx?mode=chinhhoso&id=" + e.CommandArgument.ToString());
        }

        int getPageCurrent()
        {
            var pageIndex = Request.QueryString["pageIndex"];
            int temp;
            int pCurrent = 1;
            if (!int.TryParse(pageIndex, out temp))
                pCurrent = 1;
            else
                pCurrent = int.Parse(pageIndex);
            return pCurrent;
        }

        void PhanTrang(int total, int pCurrent, string baseLink)
        {
            Paging paGing = new Paging(Hang.PAGESIZE);
            string resultPaging = paGing.CreatePaging(total, pCurrent, baseLink);
            if (string.IsNullOrEmpty(resultPaging))
                divPaging.Visible = false;
            else
            {
                divPaging.InnerHtml = resultPaging;
            }
        }

        protected void bntTimKiem_Click(object sender, EventArgs e)
        {
            divDanhsachketqua.Visible = true;
            var key = txtTimKiem.Text;
            if (!string.IsNullOrEmpty(key))
            {
                var ls = HoSoBLL.getListByKey(key, Hang.PAGESIZE, getPageCurrent());
                gridHoSo.DataSource = ls;
                gridHoSo.DataBind();
                PhanTrang(HoSoBLL.getTotalByKey(key), getPageCurrent(), "../Modules/Admin.aspx?mode=hoso&");
            }
            else
            {
                gridHoSo.DataSource = null;
                gridHoSo.DataBind();
                PhanTrang(0, 0, "../Modules/Admin.aspx?mode=hoso&");
            }
        }
    }
}